﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.Core.DBUtility;

namespace Microhard.Permission.MVCFilter
{
    public class BeforeBatchDeleteActionFilter : IActionDataFilter
    {
        #region IActionDataFilter Members

        public bool FilterAction(System.Web.Mvc.ActionExecutingContext filterContext, Models.User currentUser, List<Models.Permission> currentPermissions, Core.DBUtility.ScopeResult dataScope)
        {
            var pkids = filterContext.ActionParameters["identities"] as List<Guid>;
            var canDel = (from i in pkids
                          where dataScope.PKID.Contains(i)
                          select i).ToList();
            if (dataScope.Scope == DataCollectionScope.All || this.IsAdminAction
                || dataScope.Scope == DataCollectionScope.Custome)
            {
                filterContext.ActionParameters["identities"] = pkids;
            }
            else
            {
                filterContext.ActionParameters["identities"] = canDel;
            }
            return true;
        }

        public Guid PKID
        {
            get;
            set;
        }
        #endregion


        public bool IsAdminAction
        {
            set;
            get;
        }
    }
}
